package com.misboot.document.service;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.misboot.document.client.SystemClient;
import com.misboot.document.constants.DriverClassName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 处理数据库权限
 *
 * @Author 湖南佐佑时代科技有限公司
 * @Version 5.4.21
 * @Email service@zuoyo.com
 * @Date 2022-06-16 13:31:39
 */
@Service("redisService")
public class RedisService {

    @Autowired
    SystemClient sysAuthDataClient;

    /**
     * 数据权限
     *
     * @return
     */
    public List<Map<String, Object>> getDataAuthListFromCache(String roleId, String driverClassName) {
        List<Map<String, Object>> dataAuthList = sysAuthDataClient.getDataAuthList();
        if (CollUtil.isEmpty(dataAuthList)) {
            return null;
        }
        List<Map<String, Object>> dataAuthListFilterByRole = new ArrayList<>();
        String role_id = "";
        for (int i = 0; i < dataAuthList.size(); i++) {
            if (DriverClassName.ORACLE_NAME.equals(driverClassName)) {
                role_id = Convert.toStr(dataAuthList.get(i).get("ROLE_ID"));
            } else {
                role_id = Convert.toStr(dataAuthList.get(i).get("role_id"));
            }
            if ((role_id).equals(roleId)) {
                dataAuthListFilterByRole.add(dataAuthList.get(i));
            }
        }
        return dataAuthListFilterByRole;
    }

}
